package dao;

import dao.BaseHibernateDAO;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;

import bean.AtcLog;
import bean.Destination;

/**
 * A data access object (DAO) providing persistence and search support for
 * Destination entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see bean.Destination
 * @author MyEclipse Persistence Tools
 */

public class DestinationDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(DestinationDAO.class);
	// property constants
	public static final String DESTINATION_NAME = "destinationName";
	public static final String DESCRIPTION = "description";
	public static final String _DLATITUDE = "DLatitude";
	public static final String _DLONGITUDE = "DLongitude";
	public static final String SHOP_OVERALL = "shopOverall";
	public static final String EXPL_OVERALL = "explOverall";
	public static final String EDUC_OVERALL = "educOverall";
	public static final String REL_OVERALL = "relOverall";
	public static final String HIST_OVERALL = "histOverall";

	public void save(Destination transientInstance) {
		Transaction ts=null;
		log.debug("saving Destination instance");
		try {
			ts=getSession().beginTransaction();
			getSession().save(transientInstance);
			log.debug("save successful");
			ts.commit();
		} catch (RuntimeException re) {
			if(ts!=null)ts.rollback();
			log.error("save failed", re);
			throw re;
		}finally{
			closeSession();
		}
	}
	public void update(AtcLog transientInstance) {
		Transaction ts=null;
		log.debug("saving User instance");
		try {
			ts=getSession().beginTransaction();
			getSession().update(transientInstance);
			log.debug("save successful");
			ts.commit();
		} catch (RuntimeException re) {
			if(ts!=null)ts.rollback();
			log.error("save failed", re);
			throw re;
		}finally{
			closeSession();
		}
	}

	public void delete(Destination persistentInstance) {
		Transaction ts=null;
		log.debug("deleting Destination instance");
		try {
			ts=getSession().beginTransaction();
			getSession().delete(persistentInstance);
			log.debug("delete successful");
			ts.commit();
		} catch (RuntimeException re) {
			if(ts!=null)ts.rollback();
			log.error("delete failed", re);
			throw re;
		}finally{
			closeSession();
		}
	}

	public Destination findById(java.lang.Integer id) {
		Transaction ts=null;
		Destination instance=null;
		log.debug("getting Destination instance with id: " + id);
		try {
			ts=getSession().beginTransaction();
			instance = (Destination) getSession().get(
					"bean.Destination", id);
			ts.commit();
		} catch (RuntimeException re) {
			if(ts!=null)ts.rollback();
			log.error("get failed", re);
			throw re;
		}finally{
			closeSession();
		}
		return instance;
	}

	public List findByExample(Destination instance) {
		Transaction ts=null;
		List results=null;
		log.debug("finding Destination instance by example");
		try {
			ts=getSession().beginTransaction();
			results = getSession().createCriteria("bean.Destination").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			ts.commit();
		} catch (RuntimeException re) {
			if(ts!=null)ts.rollback();
			log.error("find by example failed", re);
			throw re;
		}finally{
			closeSession();
		}
		return results;
	}

	public List findByProperty(String propertyName, Object value) {
		Transaction ts=null;
		List results=null;
		log.debug("finding Destination instance with property: " + propertyName
				+ ", value: " + value);
		try {
			ts=getSession().beginTransaction();
			String queryString = "from Destination as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			results=queryObject.list();
			ts.commit();
		} catch (RuntimeException re) {
			if(ts!=null)ts.rollback();
			log.error("find by property name failed", re);
			throw re;
		}finally{
			closeSession();
		}
		return results;
	}

	public List findByDestinationName(Object destinationName) {
		return findByProperty(DESTINATION_NAME, destinationName);
	}

	public List findByDescription(Object description) {
		return findByProperty(DESCRIPTION, description);
	}

	public List findByDLatitude(Object DLatitude) {
		return findByProperty(_DLATITUDE, DLatitude);
	}

	public List findByDLongitude(Object DLongitude) {
		return findByProperty(_DLONGITUDE, DLongitude);
	}

	public List findByShopOverall(Object shopOverall) {
		return findByProperty(SHOP_OVERALL, shopOverall);
	}

	public List findByExplOverall(Object explOverall) {
		return findByProperty(EXPL_OVERALL, explOverall);
	}

	public List findByEducOverall(Object educOverall) {
		return findByProperty(EDUC_OVERALL, educOverall);
	}

	public List findByRelOverall(Object relOverall) {
		return findByProperty(REL_OVERALL, relOverall);
	}

	public List findByHistOverall(Object histOverall) {
		return findByProperty(HIST_OVERALL, histOverall);
	}

	public List findAll() {
		Transaction ts=null;
		List results=null;
		log.debug("finding all Destination instances");
		try {
			ts=getSession().beginTransaction();
			String queryString = "from Destination";
			Query queryObject = getSession().createQuery(queryString);
			results=queryObject.list();
			ts.commit();
		} catch (RuntimeException re) {
			if(ts!=null)ts.rollback();
			log.error("find all failed", re);
			throw re;
		}finally{
			closeSession();
		}
		return results;
	}

	public Destination merge(Destination detachedInstance) {
		Transaction ts=null;
		Destination result=null;
		log.debug("merging Destination instance");
		try {
			ts=getSession().beginTransaction();
			result = (Destination) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			ts.commit();
		} catch (RuntimeException re) {
			if(ts!=null)ts.rollback();
			log.error("merge failed", re);
			throw re;
		}finally{
			closeSession();
		}
		return result;
	}

	public void attachDirty(Destination instance) {
		Transaction ts=null;
		log.debug("attaching dirty Destination instance");
		try {
			ts=getSession().beginTransaction();
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
			ts.commit();
		} catch (RuntimeException re) {
			if(ts!=null)ts.rollback();
			log.error("attach failed", re);
			throw re;
		}finally{
			closeSession();
		}
	}

	public void attachClean(Destination instance) {
		Transaction ts=null;
		log.debug("attaching clean Destination instance");
		try {
			ts=getSession().beginTransaction();
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
			ts.commit();
		} catch (RuntimeException re) {
			if(ts!=null)ts.rollback();
			log.error("attach failed", re);
			throw re;
		}finally{
			closeSession();
		}
	}
}